import strutils

const sharps = "A A# B C C# D D# E F F# G G#".splitWhiteSpace
const flats = "A Bb B C Db D Eb E F Gb G Ab".splitWhiteSpace
const useFlats = "F Bb Eb Ab Db Gb d g c f bb eb".splitWhiteSpace 

proc normalize(startingNote: string): string = 
  result = startingNote
  result[0] = startingNote[0].toUpperAscii

proc scale*(startingNote: string, intervals = "m".repeat(12)): seq[string] =
  let tones = if startingNote in useFlats: flats else: sharps
  
  var index = tones.find(startingNote.normalize)
  for m in intervals:
    result.add tones[index]
    index += (if m == 'm': 1 elif m == 'M': 2 else: 3)
    if index >= tones.len:
      index.dec tones.len
    